package com.software.car.common.entity_change;

import com.software.car.entity.vo.ModelOptionVo;
import com.software.car.entity.vo.ModelSimpleVo;
import com.software.car.entity.vo.ModelVo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

/**
 * @Author 魔法はまだ解けない
 * @Date 2021/3/19
 */

@Mapper
public interface ModelChangeMapper {
    ModelChangeMapper INSTANCE = Mappers.getMapper(ModelChangeMapper.class);


    @Mapping(target = "typeName", expression = "java(changeType(modelVo.getType()))")
    @Mapping(target = "stateName", expression = "java(changeState(modelVo.getState()))")
    ModelVo modelToVo(ModelVo modelVo);


    @Mapping(target = "stateName", expression = "java(changeState(modelVo.getState()))")
    ModelSimpleVo simpleModelToVo(ModelSimpleVo modelVo);


    default String changeType(Integer type) {
        if (type == null) {
            return null;
        }
        if (type == 1) {
            return "单选型模板";
        }
        if (type == 2) {
            return "多选型模板";
        }
        return "未定义";
    }

    default String changeState(Integer state) {
        if (state == null) {
            return null;
        }
        if (state == 1) {
            return "创建完成";
        }
        if (state == 2) {
            return "使用中";
        }
        if (state == 3) {
            return "停用";
        }
        return "未定义";
    }

}
